let expess = require('express');
let router = expess.Router()

let mgdb = require('../../utils/mgdb')

//所有列表接口
router.get('/:listname',(req,res,next)=>{
  console.log("555");

  // res.setHeader('Access-Control-Allow-Origin', req.headers.origin)
  
    // console.log("a" ,req);
  // console.log('news/xx',req.query._page,req.query._limit,req.body.q,req.headers._sort);

  let collectionName = req.params.listname;
  let {_page,_limit,_sort,q} = req.query;

  mgdb.findList({collectionName,_page,_sort,_limit,q}).then(
    result => setTimeout(()=>res.send(result),0)
  ).catch(
    err => res.send(err) 
  )

})


router.get('/:listname/:_id/:sc',(req,res,next)=>{
  // console.log('news/xx/id',req.query._page,req.query._limit,req.body.q,req.headers._sort)
  let collectionName = req.params.listname;
  let _id = req.params._id;
  let sc = req.params.sc;
console.log("6666666");
mgdb.xiugai({collectionName,_id,sc}).then(
  result => res.send(result)
).catch(
  err => res.send(err) 
)
 
})
//所有详情结构
router.get('/:listname/:_id',(req,res,next)=>{
  console.log("77");
  // console.log('news/xx/id',req.query._page,req.query._limit,req.body.q,req.headers._sort)
  let collectionName = req.params.listname;
  let _id = req.params._id;

  mgdb.findDetail({collectionName,_id}).then(
    result => res.send(result)
  ).catch(
    err => res.send(err) 
  )
})


module.exports = router;